home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / BarGraph < prev    next >
Text File  |  1994-06-25  |  2KB  |  90 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeskLib:WimpSWIs.h"
  4.  
  5. #include "Shell.Extra.h"
  6. #include "Shell.BarGraph.h"
  7. #include "Shell.SafeAlloc.h"
  8.  
  9.  
  10.  
  11.  
  12.  
  13. typedef struct    {
  14.     int    spacing;
  15.     int    barwidth;
  16.     int    *data;
  17.     int    numbars;
  18.     int    forecol, backcol;
  19.     }
  20.     Shell_barinfo;
  21.  
  22.  
  23. static void Shell_BarRedrawer(
  24.     Shell_convertpoint    convert,
  25.     wimp_point        rectsize,
  26.     void            *reference,
  27.     const wimp_rect        *redrawrect
  28.     )
  29.  
  30. {    Shell_barinfo    *barinfo = (Shell_barinfo *) reference;
  31.     int        imin, imax, i;
  32.  
  33. imin = redrawrect->min.x / barinfo->spacing;
  34. imax = redrawrect->max.x / barinfo->spacing + 1;
  35.  
  36. Shell_MakeGE( imin, 0);
  37. Shell_MakeLE( imax, barinfo->numbars);
  38.  
  39. for ( i=imin; i<imax; i++)    {
  40.     int y = (int) barinfo->data[i];
  41.     int x = i*barinfo->spacing;
  42.  
  43.     Wimp_SetColour( barinfo->forecol);
  44.     Shell_RectangleFill2(
  45.         x, 0,
  46.         x + barinfo->barwidth, y,
  47.         convert);
  48.  
  49.     if ( y!=rectsize.y)    {
  50.         Wimp_SetColour( barinfo->backcol);
  51.         Shell_RectangleFill2(
  52.             x, y,
  53.             x + barinfo->barwidth, rectsize.y,
  54.             convert
  55.             );
  56.         }
  57.     }
  58.  
  59. return;
  60. }
  61.  
  62.  
  63.  
  64.  
  65. Shell_rectblock *Shell_AddBarGraph(
  66.     Shell_windblock *wind,
  67.     int x, int y,
  68.     int numbars, int spacing, int barwidth, int maxheight,
  69.     int *data,
  70.     int forecol, int backcol
  71.     )
  72. {
  73. Shell_barinfo    *barinfo = (Shell_barinfo *) Shell_SafeMalloc( sizeof( Shell_barinfo));
  74. Shell_rectblock    *rect;
  75.  
  76. barinfo->spacing    = spacing;
  77. barinfo->barwidth    = barwidth;
  78. barinfo->data        = data;
  79. barinfo->numbars    = numbars;
  80. barinfo->forecol    = forecol;
  81. barinfo->backcol    = backcol;
  82.  
  83. rect = Shell_AddRectangle3( wind, x, y, spacing*numbars, maxheight, Shell_BarRedrawer, barinfo);
  84. Shell_MakeRectIcon( rect, forecol, backcol, "r2");
  85. return rect;
  86. }
  87.  
  88.  
  89.  
  90.